#include "stdafx.h"
#include "RectGage.h"
#include "RectElement.h"

RectGage::RectGage()
:m_fGageRate(0.5f)
,m_bIsVertical(FALSE)
{}

RectGage::~RectGage()
{}

void RectGage::Create(RectElement* pRectElement, int nPosX, int nPosY, int nWidth, int nHeight, float fRate)
{
	m_fGageRate = fRate;
	RectStatic::Create(pRectElement, nPosX, nPosY, nWidth, nHeight);
}

void RectGage::ChangeSize()
{
	assert(m_pRectElement != NULL);

	float fWidth	 = (m_bIsVertical) ? float(m_nWidth) : m_nWidth * m_fGageRate;
	float fHeight	 = (m_bIsVertical) ? float(int(m_nHeight * m_fGageRate)) : float(m_nHeight);
	float fPosX		 = float(m_nPosX);
	float fPosY		 = (m_bIsVertical) ? float(m_nPosY + m_nHeight - fHeight) : float(m_nPosY);	

	float fTexLeft   = 0.f;
	float fTexRight  = (m_bIsVertical) ? 1.f : m_fGageRate;
	float fTexTop    = (m_bIsVertical) ? 1.f - m_fGageRate : 0.f;
	float fTexBottom = 1.f;

	m_pRectElement->SetPos(fPosX, fPosY, fWidth, fHeight, fTexLeft, fTexRight, fTexTop, fTexBottom);
}